//
//  YCSalesStructureViewController.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/6/8.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCSalesStructureViewController.h"
#import "JX_WebView.h"
#import "YCSellerInfoTableViewCell.h"
#import "YCSellerInfoModel.h"
@interface YCSalesStructureViewController ()<WKUIDelegate,UIWebViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) JX_WebView *webView;

@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong)UILabel *labelJianjie;
@property(nonatomic,strong)NSArray *allData;
@end

@implementation YCSalesStructureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的销售架构";
    
    self.view.backgroundColor = [UIColor whiteColor];
    /*
    //进行配置控制器
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    //实例化对象
    configuration.userContentController = [WKUserContentController new];
    
    WKPreferences *preferences = [WKPreferences new];
    preferences.javaScriptCanOpenWindowsAutomatically = YES;
    configuration.preferences = preferences;
    
    
    self.webView =[[JX_WebView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 64)configuration:configuration];
    [self.view addSubview:_webView];
    
    _webView.backgroundColor = [UIColor clearColor];
    
    NSString * urlString = [NSString stringWithFormat:@"http://wx-heartorg.yk2020.com/weixin/index.php?m=Expert&c=Huzhu&a=fx&expert_id=%@&yw_id=%@",[YCUserTool sharedTools].expertID,yw_id];
    NSLog(@"urlString = %@",urlString);
    _webView.UIDelegate = self;
    
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
    [_webView webViewLoadStart:^(WKWebView *webview,WKNavigation *navigation) {
        [self presentLoadingTips:nil];
    } Finish:^(WKWebView *webview,WKNavigation *navigation) {
        [self dismissTips];
    } Fail:^(WKWebView *webview,WKNavigation *navigation) {
        [self dismissTips];
    }];
    
    */
    
    [DownloadData post:kGetSellerInfo params:@{@"member_id":[YCUserTool sharedTools].expertID} success:^(id json) {
        self.allData = [YCSellerInfoModel mj_objectArrayWithKeyValuesArray:json];
        self.labelJianjie.text = [NSString stringWithFormat:@"   我是哪些人的间接销售者(%zd人)",self.allData.count];
        [self.tableView  reloadData];
        NSLog(@"json = %@",json);
    } failure:^(NSError *error) {
        
    }];
    
    
    
    UILabel *labelTitle = [[UILabel alloc]init];
    labelTitle.text = @"销售结构明细展示";
    labelTitle.textAlignment = NSTextAlignmentCenter;
    labelTitle.font = [UIFont boldSystemFontOfSize:18];
    [self.view addSubview:labelTitle];
    
    UIView *lineView1 = [[UIView alloc]init];
    lineView1.backgroundColor = RGB(243, 243, 243);
    [self.view addSubview:lineView1];
    
    
    
    UIView *lineView2 = [[UIView alloc]init];
    lineView2.backgroundColor = RGB(243, 243, 243);
    [self.view addSubview:lineView2];
    
    UILabel *labelJianjie = [[UILabel alloc]init];
    labelJianjie.text = @"   我是哪些人的间接销售者(0人)";
    self.labelJianjie = labelJianjie;
    labelJianjie.font = [UIFont systemFontOfSize:15];
    labelJianjie.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:labelJianjie];
    
    
    UITableView *tableView = [[UITableView alloc]init];
    self.tableView = tableView;
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.tableFooterView = [UIView new];
    [self.view addSubview:tableView];
    
    
    
    
    __weak __typeof(&*self)mySelf = self;
    
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(mySelf.view.mas_top).mas_offset(0);
        make.left.mas_equalTo(mySelf.view.mas_left).mas_offset(0);
        make.right.mas_equalTo(mySelf.view.mas_right);
        make.height.mas_equalTo(50);
    }];
    
    
    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(labelTitle.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(labelTitle.mas_left).mas_offset(0);
        make.right.mas_equalTo(labelTitle.mas_right);
        make.height.mas_equalTo(10);
    }];
    
    [labelJianjie mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lineView1.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(labelTitle.mas_left).mas_offset(0);
        make.right.mas_equalTo(labelTitle.mas_right);
        make.height.mas_equalTo(35);
    }];
    
    
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(labelJianjie.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(labelJianjie.mas_left).mas_offset(0);
        make.right.mas_equalTo(labelJianjie.mas_right);
        make.height.mas_equalTo(10);
    }];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lineView2.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(labelJianjie.mas_left).mas_offset(0);
        make.right.mas_equalTo(labelJianjie.mas_right);
        make.bottom.mas_equalTo(mySelf.view).mas_offset(-20);
    }];

    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.allData.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    YCSellerInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[YCSellerInfoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
    }

    cell.model = self.allData[indexPath.row];
    return cell;
}


@end
